cd ${work}5_reg_analysis

local ylist		"log_quantity log_price log_mc log_mu log_quality ihs_var_profits_nos ihs_profits"
local felist	`" "IY FP" "IY FP FY" "PY FP FY" "'
local wlist		`" "c.sales##c.sales##c.sales##c.sales" "" "" "'
local x			"exp dest dest_sq"

use temp\regsample_ipt, clear

gen z_int = tdcinitiative_2*log(sales)

eststo clear
local col=1	
foreach fe of local felist {
    
	local row=1
	local w : word `col' of `wlist'
	local estlist
	
foreach y of local ylist {

	cap gen x_`row'=.
	replace x_`row'=treated_2
	lab var x_`row' "$ \overline{support fht}_{fht} $"
	cap gen x_int_`row'=.
	replace x_int_`row'=treated_2 * log(sales)
	lab var x_int_`row' "$ \overline{support fht}_{fht} \times $ ln(lagged total sales)"
	local x_`row'
	foreach v of local x {
		cap gen `v'_`row'=`v'
		lab var `v'_`row' "`:var lab `v''"
		local x_`row' `x_`row'' `v'_`row'
	}		
	eststo est`row' : ivreghdfe `y' (x_`row' x_int_`row' = tdcinitiative_2 z_int) `x_`row'' `w', a(`fe') cl(F)
	local estlist `estlist' est`row'
	local ++row
	local N = e(N)
	local F = e(widstat)
	
}
	
	eststo stacked_`col' : appendmodels `estlist'
	eststo drop est*
	qui estadd scalar N `N'
	qui estadd scalar F `F'
	qui estadd local FE `fe'
	if "`w'"!=""	qui estadd local SC "Yes"
	if "`w'"==""	qui estadd local SC "No"
	if "`x'"=="" qui estadd local EC "No"
	if "`x'"!="" qui estadd local EC "Yes"

	local ++col
	
}	

local lablist
local N : word count `ylist'
local n=1
foreach y of local ylist {
	local lab : var lab `y'
	local lablist `"`lablist' x_`n' "\textit{`lab'}" "'
	local ++n
}	
	
esttab using output\table_a13.tex, replace booktabs se label nomtitles ///
	title("2SLS Estimates of Export Support on Firm-Product-Year Outcomes across Firm Size") star(* 0.1 ** 0.05 *** 0.01) keep(x_*) ///
	stats(N F FE SC EC , labels("Observations" "IV F-stat" "Fixed Effects" "Size Control" "Export Controls") fmt(%10.0fc %10.0fc "" "" "")) refcat(`lablist', nolabel)